package javacommon.web.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
/**
 * 字符编码过滤器
 * @author zhengwei lastmodified 2013年9月7日
 *
 */
public class EncodingFilter implements Filter {

	public void destroy() {
	}

	// 真正处理过滤逻辑的地方
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		//1.前置处理
		System.out.println("编码过滤器，正在发挥作用。。。。。。");
		request.setCharacterEncoding(encoding);
		//2.继续过滤链(把皮球传出去，否则请求过程就中断了)
		chain.doFilter(request, response);
		//3.后置处理
	}

	public void init(FilterConfig fConfig) throws ServletException {
		encoding = fConfig.getInitParameter("encoding");
	}
	private String encoding;
}
